/**
 * 
 */
package main;

import java.util.Date;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.LazyOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import com.ccb.channel.atm.AtmMapper;
import com.ccb.channel.atm.AtmReducer;

/**
 * @author congyang
 *
 */
public class Atm {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		String output = "dedup_out\\atm";
		String input = "dedup_in\\atm\\atm.txt";
		runJob(input, output);
	}

	public static void runJob(String inpath, String outpath) throws Exception {

		long stime = new Date().getTime();

		Configuration conf = new Configuration();
		conf.addResource("pom.xml");
		conf.set("textinputformat.record.delimiter", "~~~\u62A5\u6587\u7ED3\u675F~~~\r\n");

		Job job = Job.getInstance(conf, "Atm");
		// job.setInputFormatClass(TrackInputFormat.class);
		job.setInputFormatClass(TextInputFormat.class);
		// job.setOutputFormatClass(TextOutputFormat.class);
		LazyOutputFormat.setOutputFormatClass(job, TextOutputFormat.class);
		job.setJarByClass(Atm.class);
		job.setMapperClass(AtmMapper.class);
		job.setReducerClass(AtmReducer.class);
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(Text.class);
		FileInputFormat.addInputPath(job, new Path(inpath));
		FileOutputFormat.setOutputPath(job, new Path(outpath));
		FileSystem.get(conf).delete(new Path(outpath), true);
		long etime = new Date().getTime();
		System.out.println((etime - stime) / 1000.0);
		System.exit(job.waitForCompletion(true) ? 0 : 1);
	}

}
